export default {
  data () {
    return {
      TSPGaugeEchart: null,
      TSPGaugeOption: {
        series: [
          {
            name: 'TSP',
            type: 'gauge',
            detail: {formatter:'{value}'},
            radius: '85%',
            min: 0,
            max: 500,
            splitLine: {
              lineStyle: {
                color: '#fff'
              }
            },
            title: {
              fontSize: 18,
              offsetCenter: [0, '-30%'],
              fontWeight: 'bolder'
            },
            axisTick: {
              lineStyle: {
                color: '#fff'
              }
            },
            pointer: {
              width: 4
            },
            axisLine: {
              show: true,
              lineStyle: {
                width: 15,
                shadowBlur: 0,
                color: [[0.2, '#27b47f'],[0.8, '#fea831'],[1, '#fa5655']]
              }
            },
            data: [{value: 1, name: 'TSP\n(ug/m³)'}]
          }
        ]
      }
    }
  },
  methods: {
    initTSPGaugeEchart () {
      let alarm = 1
      let color = [[0.2, '#85e7c2'], [0.8, '#ffdeb1'], [1, '#ffe2e2']]
      let TSPWARN = Number.parseInt(this.groupParams.TSPWARN || 0)
      let TSPALARM = Number.parseInt(this.groupParams.TSPALARM || 0)
      let max = TSPALARM + 100
      let normal = TSPWARN / max
      let warngin = ((TSPALARM - TSPWARN) / max) + normal

      // 正常状态
      if (this.projectEnvironmentData.tsp < TSPWARN) {
        let pmTwo = this.projectEnvironmentData.tsp / TSPWARN
        let pmNormal = normal * pmTwo
        color = [[pmNormal, '#30d394'], [normal, '#85e7c2'], [warngin, '#fff6ed'], [alarm, '#ffe3e1']]
      }
      // 预警状态
      if (this.projectEnvironmentData.tsp > TSPWARN && this.projectEnvironmentData.tsp < TSPALARM) {
        let pmTwo = this.projectEnvironmentData.tsp / max
        color = [[normal, '#30d394'], [pmTwo, '#fda730'], [warngin, '#ffdeb1'], [alarm, '#fea8a9']]
      }
      // 报警
      if (this.projectEnvironmentData.tsp > TSPALARM) {
        let pmTwo = this.projectEnvironmentData.tsp / max
        color = [[normal, '#30d394'], [warngin, '#fea831'], [pmTwo, '#fa5655'], [alarm, '#ffe2e2']]
      }
      this.TSPGaugeOption.series[0].axisLine.lineStyle.color = color
      this.TSPGaugeOption.series[0].data = []
      this.TSPGaugeOption.series[0].max = max
      this.TSPGaugeOption.series[0].data.push({value: this.projectEnvironmentData.tsp || 0, name: 'TSP\n(ug/m³)'})
      this.TSPGaugeEchart = this.$Echarts.init(this.$refs.gaugeTSPEnvironment)
      this.TSPGaugeEchart.setOption(this.TSPGaugeOption)
    }
  }
}
